package com.marvels.approve.loan.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.marvels.approve.loan.dto.LoanApprovalDTO;
import com.marvels.approve.loan.service.ILoanApprovalService;
import com.marvels.common.dto.MarvelsResultDTO;
import com.marvels.common.exception.MarvelsBusinessException;
import com.marvels.common.exception.MarvelsErrorCode;
import com.marvels.common.utils.MarvelsLogUtil;

/**审批复核
 * @author hejie
 */
@RestController
@RequestMapping("approve/approval/service")
public class LoanApprovalController {
	@Autowired
	private ILoanApprovalService loanApprovalService;
	/**查询相关内容
	 * @param loanChecking
	 * @return
	 */
	@RequestMapping("qapproval")
	public MarvelsResultDTO queryApproval(@RequestBody LoanApprovalDTO loanApproval) {
		try {
			LoanApprovalDTO loanApprovalDTO = loanApprovalService.findLoanApproval(loanApproval);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),loanApprovalDTO);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error(">>>>>>审批复核FAIL:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(), e.getMessage(), e.getMessage());
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error(">>>>>>审批复核异常:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(), MarvelsErrorCode.ERROR.getDesc(),
					"审批复核异常");
		}
	}
	
	/**保存审批复核信息
	 * @param loanChecking
	 * @return
	 */
	@RequestMapping("addapproval")
	public MarvelsResultDTO addApproval(@RequestBody LoanApprovalDTO loanApprovalRequest) {
		try {
			LoanApprovalDTO loanApprovalDTO = this.loanApprovalService.saveLoanApproval(loanApprovalRequest);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),loanApprovalDTO);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error(">>>>>>征信复核保存FAIL:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(), e.getMessage(), e.getMessage());
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error(">>>>>>征信复核保存:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(), MarvelsErrorCode.ERROR.getDesc(),
					"征信复核保存");
		}
	}
	/**审批复核信息
	 * @param loanChecking
	 * @return
	 */
	@RequestMapping("complateapproval")
	public MarvelsResultDTO complateApproval(@RequestBody LoanApprovalDTO loanApprovalRequest) {
		try {
			LoanApprovalDTO loanApprovalDTO = this.loanApprovalService.complateLoanApproval(loanApprovalRequest);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),loanApprovalDTO);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error(">>>>>>征信复核完成任务FAIL:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(), e.getMessage(), e.getMessage());
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error(">>>>>>征信复核完成任务:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(), MarvelsErrorCode.ERROR.getDesc(),
					"征信复核完成任务");
		}
	}
}
